home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tcclib.zip / WINDEMO.C < prev    next >
Text File  |  1989-01-02  |  3KB  |  146 lines

  1. #include <conio.h>
  2. #include <alloc.h>
  3. #include <mem.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <assert.h>
  7. #include <time.h>
  8. #include "window.h"
  9.  
  10. #define NUMWINDS 20
  11.  
  12. windowtype *windows[NUMWINDS+1];
  13. windowtype *promptwindow;
  14.  
  15. main()
  16. {
  17.     int i;
  18.     int left,right,top,bottom;
  19.     char title[]= "- Window XX -";
  20.     int  win;
  21.     int color;
  22.     int ch;
  23.  
  24. /*    randomize(); */
  25.     srand(3);
  26.  
  27.     textattr(0x7);
  28.  
  29.     clrscr();
  30.  
  31.     for (i=0;i<20;i++)
  32.         cputs("This is a test of this program. This is not in a window\r\n");
  33.  
  34.     for (i=0;i<NUMWINDS; i++)
  35.     {
  36.         top     = random(10)+2;
  37.         left     = random(58)+2;
  38.         bottom  = top  + 10;
  39.         right   = left + 20;
  40.  
  41.         do
  42.         {
  43.             color = random(127)+1;
  44.         }
  45.         while ( (color & 0xF) == ((color&0xF0) >> 4) );
  46.  
  47.         title[9]  = i/10+0x30;
  48.         title[10] = i%10+0x30;
  49.  
  50.         if ( (windows[i] = makewindow(left,top,right,bottom,color,3,title))
  51.              == NULL)
  52.         {
  53.             switch(windowerr)
  54.             {
  55.                 case WE_OMEM:
  56.                     window(1,1,80,25);
  57.                     cputs("Not enough memory to open window.\r\n");
  58.                     return 1;
  59.                 case WE_BADC:
  60.                     window(1,1,80,25);
  61.                     cputs("Bad coordinates for window.\r\n");
  62.                     return 2;
  63.                 default:
  64.                 case WE_OK:
  65.                     window(1,1,80,25);
  66.                     cputs("Internal Error: makewindow\r\n");
  67.                     return 5;
  68.             };
  69.         }
  70.         cputs("This is a test of this program.\r\n");
  71.         cputs("This is a test of this program.\r\n.");
  72.     }
  73.  
  74.     promptwindow = makewindow(18,12,62,12,0x1E,2,"");
  75.     winwrite(promptwindow," Demonstration of Background Window Writing");
  76.     do
  77.     {
  78.         do
  79.         {
  80.             for ( i=0; i<NUMWINDS; i++)
  81.                 winwrite(windows[i], "This is a test ");
  82.         }
  83.         while( !kbhit() );
  84.         ch = getch()-'0';
  85.         if ( ch >=0 && ch < NUMWINDS )
  86.         {
  87.             shiftwindow(windows[ch]);
  88.             shiftwindow(promptwindow);
  89.         }
  90.         else
  91.             break;
  92.     }
  93.     while (1);
  94.     deletewindow(promptwindow);
  95.  
  96.     windows[NUMWINDS]=NULL;
  97.     for (i=0; i<NUMWINDS; i++)
  98.     {
  99.  
  100. #ifdef PROMPT
  101.         if ( (promptwindow = makewindow(20,12,60,12,0x1E,1," Delete Window ")
  102.              ) == NULL )
  103.         {
  104.             window(1,1,80,25);
  105.             cputs("Not enough memory to make prompt window.\r\n");
  106.             return 1;
  107.         }
  108.         win = NUMWINDS;
  109.         while (windows[win] == NULL)
  110.         {
  111.             char buf[7];
  112.  
  113.             clrscr();
  114.             cputs("Enter window number to delete: ");
  115.             buf[0] = 5;
  116.             cgets(buf);
  117.             win = atoi(&buf[2]);
  118.             if (win == -1)
  119.                 exit(0);
  120.         }
  121.         deletewindow(promptwindow);
  122. #else
  123.         win = i;
  124. #endif
  125.         if ( shiftwindow(windows[win]) )
  126.         {
  127.             window(1,1,80,25);
  128.             cputs("Not enough memory available to shift to window\r\n");
  129.             return 1;
  130.         }
  131.  
  132. #ifdef PROMPT
  133.         getch();
  134. #endif
  135.  
  136.         if ( deletewindow(windows[win]) )
  137.         {
  138.             window(1,1,80,25);
  139.             cputs("Window %d is not the current window.\r\n");
  140.             return 1;
  141.         }
  142.         windows[win] = NULL;
  143.     }
  144.     return 0;
  145. }
  146.